home *** CD-ROM | disk | FTP | other *** search
- "viewManager.self,v 1.12 1993/07/18 20:24:10 richards Exp"
- "viewManager - self internal analogue of a display"
-
- traits _AddSlotsIfAbsent: (| ^ views* = () |)
- prototypes _AddSlotsIfAbsent: (| ^ views* = () |)
- mixins _AddSlotsIfAbsent: (| ^ views* = () |)
- oddballs _AddSlotsIfAbsent: (| ^ views* = () |)
-
- traits views _AddSlotsIfAbsent: (| ^ viewManager = () |)
-
- "remove this later!"
- traits views viewManager _Mirror size > 0 ifTrue: [viewManager shutdown]
-
- traits views viewManager _Define: (|
-
- parent*** = traits clonable.
- comparisons** = mixins identity.
-
- copying* = (|
-
- "this will give us a dead display proxy"
- ^ copy = (((((resend.copy display: display copy)
- eye: eye copy)
- eventProcess: eventProcess copy)
- managedViews: managedViews copyRemoveAll)
- releasedViews: releasedViews copyRemoveAll).
- |).
-
- lifeAndDeath* = (|
-
- ^ open = (open: '').
- ^ open: name = (open: name IfFail: [^error: 'ViewManager open']).
- ^ open: name IfFail: block = (copy initialise: name IfFail: block).
-
- _ howManyAttempts = 25.
-
- "this will need to be reworked if anything else can fail"
- _ initialise: name IfFail: block = (|attempts|
- howManyAttempts do: [
- display: display open: name IfFail: [display].
- display isLive ifTrue: [completeInit. ^self]
- warning: 'retrying open display'].
- block value).
-
- "this finishes the initialisation once this display is open"
- _ completeInit = (
- initColours.
- initBitmaps.
- spawnInputProcess.
- managerList addLast: self.
- warning: 'gc is a kludge'.
- initFonts.
- gc: xlib graphicsContext
- createForSameScreenAs: rootWindow.
- gc foreground: display screen blackPixel.
- gc font: fixedFont fid.
- gcb: xlib graphicsContext
- createForSameScreenAs: rootWindow.
- gcb foreground: display screen whitePixel.
- gcb font: fixedFont fid.
- initGCs.
- ).
-
-
- ^ close = (managerList remove: self.
- stopInputProcess.
- display close).
-
- ^ flush = (display flush).
- ^ isOpen = (display isLive).
- ^ isRunning = (eventProcess active).
-
- "some operations also run down the managerList"
-
- _ managerList = list copy.
-
- ^ someManager =
- (managerList isEmpty ifTrue: [open]. managerList first).
-
- ^ shutdown = (managerList do: [|:m| m close]).
- ^ closeAll = (managerList do: [|:m| m close]).
- ^ flushAll = (managerList do: [|:m| m flush]).
-
- |).
-
-
- inputProcessHandling* = (|
-
- "start up the event watcher process"
- "this process runs asynchronously, gets events, and sends us
- to handle. Currently, each event is run synchronously"
- spawnInputProcess =
- (eye: eventWatcher copyForDisplay: display SendingTo: self.
- eventProcess: process copySend:
- message copy receiver: eye Selector: 'watch'.
- eventProcess resume).
-
- stopInputProcess = (eventProcess abort).
-
- restart = (nukeOldProc. spawnInputProcess).
-
- _ nukeOldProc = (eventProcess _StackDepthIfFail: [^ 42].
- stopInputProcess).
-
- |).
-
- _ viewManagement* = (|
-
- "other window proxies may = this view, but they won't == it"
- "this happens when an event returns a window, for example"
- "this dictionary is used to canonicalise a window proxy"
- "turning it into the view managed by this display"
-
- "manage adds a view into the eveny handling list"
- "release removes it, and adds it to a 'releasedViews'"
- "list. This happens with the view is unrealised - there may"
- "still be events outstanding (notably destroyNotify)"
-
- "because of strangnesses with window proxies, we actually"
- "index this by the window's X id"
-
- manage: view For: window = (managedViews at: window id Put: view).
-
- find: window = (
- managedViews at: window id IfAbsent: [
- (releasedViews includes: window id)
- ifFalse: [warning: 'I can\'t find a window'].
- eventMixin]).
-
- release: view For: window = (
- ((managedViews at: window id IfAbsent: nil) == nil)
- ifTrue: [ warning: 'bug *somewhere*' ].
- managedViews remove: view
- IfAbsent: [warning: 'I can\'t find a window, again'].
- releasedViews add: window id.
- window kill. "Belt and braces"
- self).
-
- "at some point we must kill off the proxy"
- "this happens when the window comes of the releasedViews"
- "list, when the destroyNotify comes in"
-
- |).
-
- _ eventHandling* = (|
-
- keyPress: event = (
- debugMessage: 'keyPress event'.
- (find: event window) keyPress: event.
- event delete.
- self. ).
-
- keyRelease: event = (
- debugMessage: 'keyRelease event'.
- (find: event window) keyRelease: event.
- event delete.
- self).
-
- buttonPress: event = (
- debugMessage: 'buttonPress event'.
- (find: event window) buttonPress: event.
- event delete.
- self).
-
- buttonRelease: event = (
- debugMessage: 'buttonRelease event'.
- (find: event window) buttonRelease: event.
- event delete.
- self).
-
- motionNotify: event = (
- debugMessage: 'motionNotify event'.
- (find: event window) motionNotify: event.
- event delete.
- self).
-
- enterNotify: event = (
- debugMessage: 'enterNotify event'.
- (find: event window) enterNotify: event.
- event delete.
- self).
-
- leaveNotify: event = (
- debugMessage: 'leaveNotify event'.
- (find: event window) leaveNotify: event.
- event delete.
- self).
-
- "focus in, out missing"
- "keymap notify missing"
-
- expose: event = (
- debugMessage: 'expose event'.
- (event count = 0) ifTrue:
- [(find: event window) expose: event].
- event delete.
- self).
-
- "graphicsExpose missing"
-
- noexpose: event = (
- debugMessage: 'noexpose event'.
- " (find: event window) noexpose: event."
- event delete.
- self).
-
-
- visibilityNotify: event = (
- debugMessage: 'visibilityNotify event'.
- event delete.
- self).
-
- "createNotify/destroyNotify missing"
-
- unmapNotify: event = (
- debugMessage: 'unmapNotify event'.
- (find: event window) unmapNotify: event.
- event delete.
- self).
-
- mapNotify: event = (
- debugMessage: 'mapNotify event'.
- (find: event window) mapNotify: event.
- event delete.
- self).
-
- "mapRequest missing"
-
- reparentNotify: event = (
- debugMessage: 'reparentNotify event'.
- event delete.
- self).
-
- configureNotify: event = (
- debugMessage: 'configureNotify event'.
- (find: event window) configureNotify: event.
- event delete.
- self).
-
- "configureRequest missing"
- "gravityNotify missing"
- "resizeRequest, circulateNotify, circulateRequest"
- "propertyNotify"
- "SelectionClear/Request/Notify"
- "ColourmapNotify, MappingNotify missing"
-
- clientMessage: event = (
- debugMessage: 'clientMessage event'.
- (event message_type = xlib wmProtocols) &&
- [(event atomAt: 0) = xlib wmDeleteWindow]
- ifTrue: [ debugMessage: 'wmDeleteWindow' ]
- False: [ debugMessage: 'unknown clientMessage event' ].
- event delete.
- self).
-
- otherEvent: event = (
- "debugMessage: 'unknown event: ', event type printString."
- event delete.
- self).
- |).
-
- ^ eventMixin = (|
- configureNotify: event = (42).
- mapNotify: event = (42).
- unmapNotify: event = (42).
- expose: event = (42).
- keyPress: event = (42).
- keyRelease: event = (42).
- buttonPress: event = (42).
- buttonRelease: event = (42).
- motionNotify: event = (42).
- enterNotify: event = (42).
- leaveNotify: event = (42).
- visibilityNotify = (42).
- |).
-
- _ colourManagement* = (|
-
- "ultimately, this should handle real colourmaps"
- "and call lookup colour rather than this :-)"
-
- _ initColours = (
- pixelColours: pixelColours copyRemoveAll.
- pixelColours at: 'white' Put: display screen whitePixel.
- pixelColours at: 'black' Put: display screen blackPixel).
-
- ^ pixel: colour = (
- pixelColours at: colour IfAbsent: [display screen blackPixel]).
-
- |).
-
- _ fontManagement* = (|
- initFonts = (
- fontCache: fontCache copyRemoveAll.
- fixedFont: display loadFont: 'fixed'.
- fontCache at: 'fixed' Put: fixedFont. " prime the cache "
- ).
-
- basicOpenFontNamed: fname = (| fid. |
- fid: display loadFont: fname IfFail: [
- warning: ('font ',fname,' not fount. Using fixed.').
- fixedFont
- ].
- ^fid
- ).
-
- openFontNamed: fname = (| fid. |
- fid: fontCache at: fname IfAbsent: [
- debugMessage: 'opening font: ',fname.
- fid: basicOpenFontNamed: fname.
- fontCache at: fname Put: fid.
- fid
- ].
- ^fid
- ).
- |).
-
- _ gcManagement* = (|
- initGCs = (| fixedFontGC. |
- gcCache: gcCache copyRemoveAll.
- fixedFontGC: allocateGcStruct.
- fixedFontGC fontId: fixedFont fid.
- fixedFontGC realiseGC.
- gcCache addFirst: fixedFontGC.
- gc: fixedFontGC gc.
- ).
-
- allocateGcStruct = ( | newGC. |
- (gcCache size > maxGCs) ifTrue: [
- newGC: gcCache removeLast.
- ] False: [
- newGC: gcCacheStruct copy.
- newGC gc: xlib graphicsContext createForSameScreenAs: rootWindow.
- ].
- newGC fontId: gc font.
- newGC lineWidth: gc lineWidth.
- newGC copyFunction: gc function.
- newGC whitePixel: gc foreground.
- newGC blackPixel: gc background.
- newGC
- ).
-
- gcWithCharacteristics: testBlock MakeIt: creationBlock = (| newGC. |
- gcCache reverseDo: [ | :aGc |
- (testBlock value: aGc) ifTrue: [
- " found the right gc "
- gcCache remove: aGc. "remove... "
- gcCache addFirst: aGc. " and move to front"
- ^aGc gc
- ].
- ].
- " didn't find what we needed. "
- newGC: allocateGcStruct.
- creationBlock value: newGC.
-
- "XXX - this could all be done in a single X protocol call "
- newGC realiseGC.
- debugMessage: ('allocated a new GC: ', newGC printString).
-
- gcCache addFirst: newGC.
- newGC gc
- ).
- gcForFont: fid = (
- gcWithCharacteristics: [ | :aGc | (aGc fontId = fid) ]
- MakeIt: [ | :aGc | aGc fontId: fid. ].
- ).
- gcWidth: width = (
- gcWithCharacteristics: [ | :aGc | (aGc lineWidth = width) ]
- MakeIt: [ | :aGc | aGc lineWidth: width ].
- ).
- gcFunction: fct = (
- gcWithCharacteristics: [ | :aGc | (aGc copyFunction = fct) ]
- MakeIt: [ | :aGc | aGc copyFunction: fct ].
- ).
- |).
-
-
- _ bitmaps* = (|
-
- "Perhaps some of this should be moved into the iconSelector, or
- elsewhere. This would let us cache bitmapMakers (raw data) as well as
- pixmaps. "
-
- ^ iconPath <- ''.
- _ defaultIcon = ''.
-
-
- _ defaultIconPathName <- '/usr/include/X11/bitmaps/escherknot'.
-
- ^ maxDepth <- 8.
-
- _ initBitmaps = (
- (iconPath = '') ifTrue: [
- iconPath: (unix environmentVariable: 'AATREE' " XXX - This just doesn't belong here "
- IfFail: [warning: 'Icon path not set'.'']) ,
- '/bitmaps' ].
- (defaultIconPathName = '') ifTrue: [
- defaultIconPathName:
- unixFile locate: defaultIcon,'.icon' InPath: iconPath
- IfFail: [error: 'defaultIcon not found'. ]].
- bitmapCache: bitmapCache copyRemoveAll.
- ).
-
- "_" findBitmap: name Window: win = (
- bitmapCache at: name IfAbsent: [|bitmap|
- bitmap: ((xBitmapMaker copy
- parseBitmapFile: locateIcon: name)
- createBitmapForSameScreenAs: win).
- bitmapCache at: name Put: bitmap.
- bitmap]
- ).
-
- ^ locateIcon: name = (
- locateIcon: name IfFail: [
- warning: 'Icon ',name, ' not found'.
- defaultIconPathName]
- ).
-
- ^ locateIcon: name IfFail: block = (
- unixFile locate: name,'.icon' InPath: iconPath IfFail: block).
-
- ^ iconExists: name = (locateIcon: name IfFail: [^false]. true).
-
- ^ flushBitmapCache = (bitmapCache removeAll).
-
- |).
-
- _ debugging* = (|
- ^ debug <- false.
- ^ debugMessage: str = ( debug ifTrue: [ str printLine ] ).
- |).
-
-
- printString = ('viewManager for ', display name).
-
- rootWindow = (display screen rootWindow display: display).
-
- ^ test = ( | barf. foo. bar. |
- barf: viewManager open.
- foo: compoundView copy name: 'foo'.
- foo addSubView: (view copy iArea: (10@10)##(280@@20)).
- foo addSubView: (view copy iArea: (10@40)##(280@@20)).
- foo addSubView: (view copy iArea: (10@70)##(280@@20)).
- foo realise map.
- bar: foo copy.
- bar realise map.
- foo flush
- ).
- |)
-
- prototypes views _AddSlotsIfAbsent: (| ^ viewManager = () |)
- prototypes views viewManager _Define: (|
-
- parent* = traits views viewManager.
-
- _ thisObjectPrints = true.
-
- ^ display <- xlib display.
-
- _ eye. "eventWatcher"
- "_" eventProcess <- process. "process the eventWatcher runs in"
-
- ^ managedViews <- dictionary.
- ^ releasedViews <- list.
-
- gc <- xlib graphicsContext. "until defaultGCOfScreen goes!"
- gcb <- xlib graphicsContext. "until defaultGCOfScreen goes!"
-
- _ pixelColours <- dictionary.
-
- _ bitmapCache <- dictionary.
-
- " Font Management "
- _ fontCache <- dictionary.
- _ fixedFont.
-
- " GC Cache "
- _ gcCache <- list.
- _ fixedFontGC.
- _ maxGCs <- 16.
- |)
-
-